<?php echo $header; ?>
<div id="content">
  <div class="breadcrumb">
    <?php foreach ($breadcrumbs as $breadcrumb) { ?>
    <?php echo $breadcrumb['separator']; ?><a href="<?php echo $breadcrumb['href']; ?>"><?php echo $breadcrumb['text']; ?></a>
    <?php } ?>
  </div>
  <?php if ($error_warning) { ?>
  <div class="warning"><?php echo $error_warning; ?></div>
  <?php } ?>
  <?php if ($success) { ?>
  <div class="success"><?php echo $success; ?></div>
  <?php } ?>
	
<?php echo $shortcut_route;?> 
  <div class="box">
    <div class="heading">
      <h1><img src="view/image/category.png" alt="" /> <?php echo $heading_title; ?></h1>
      <div class="buttons"><a onclick="location = '<?php echo $insert; ?>'" class="button"><span><?php echo $button_insert; ?></span></a><a onclick="$('#form').submit();" class="button"><span><?php echo $button_delete; ?></span></a></div>
      <div style="position: relative;top:8px;left: 20px;overflow: hidden;">
          <select name="parent_id" style="width:250px;" onchange="filter()">
              <option value=""></option>
              <?php foreach ($parents as $parent){ ?>
                <?php if ($parent['article_category_id']==$parent_id){ ?>
                  <option value="<?php echo $parent['article_category_id'];?>" selected="selected"><?php echo $parent['name'];?></option>
                <?php } else{ ?>
                  <option value="<?php echo $parent['article_category_id'];?>"><?php echo $parent['name'];?> <?php echo $parent['total']; ?></option> 
                <?php }?>
              <?php }?>
              </select>
              <span style="margin-left:5px;">Lọc theo danh mục</span>
      </div>
    </div>
    <div class="content">
      <form action="<?php echo $delete; ?>" method="post" enctype="multipart/form-data" id="form">
       <p align="center"></p>
        <table class="list">
          <thead>
            <tr>
              <td width="1" style="text-align: center;"><input type="checkbox" onclick="$('input[name*=\'selected\']').attr('checked', this.checked);" /></td>
              <td class="center" width="1">Image</td>
              <td class="left"><?php echo $column_name; ?></td>
              <td class="right"><?php echo $column_sort_order; ?></td>
              <td class="right"><?php echo $column_status; ?></td>
              <td class="right"><?php echo $column_action; ?></td>
            </tr>
          </thead>
          <tbody>
          
           <tr class="filter">
              <td></td>
              <td></td>
              <td><input type="text" name="filter_name" value="<?php echo $filter_name; ?>" onchange="filter()"/></td>
              <td></td>
              <td class="right"><select onchange="filter()" name="filter_status">
                  <option value="*"></option>
                  <?php if ($filter_status) { ?>
                  <option value="1" selected="selected"><?php echo $text_enabled; ?></option>
                  <?php } else { ?>
                  <option value="1"><?php echo $text_enabled; ?></option>
                  <?php } ?>
                  <?php if (!is_null($filter_status) && !$filter_status) { ?>
                  <option value="0" selected="selected"><?php echo $text_disabled; ?></option>
                  <?php } else { ?>
                  <option value="0"><?php echo $text_disabled; ?></option>
                  <?php } ?>
                </select></td>
             
              <td align="right"><a onclick="filter();" class="button"><span><?php echo $button_filter; ?></span></a></td>
            </tr>
            <?php if ($categories) { ?>
            <?php foreach ($categories as $category) { ?>
            <tr>
              <td style="text-align: center;"><?php if ($category['selected']) { ?>
                <input type="checkbox" name="selected[]" value="<?php echo $category['article_category_id']; ?>" checked="checked" />
                <?php } else { ?>
                <input type="checkbox" name="selected[]" value="<?php echo $category['article_category_id']; ?>" />
                <?php } ?></td>
              <td style="text-align: center;"><img src="<?php echo $category['image']; ?>" alt="<?php echo $category['name']; ?>" style="padding: 1px; margin:3px 0; border: 1px solid #DDDDDD;" /></td>
              <td class="left"><?php echo $category['name']; ?> <?php echo $category['total']; ?></td>
              <td class="right"><?php echo $category['sort_order']; ?></td>
              <td class="right"><?php echo $category['status']; ?></td>
              <td class="right"><?php foreach ($category['action'] as $action) { ?>
                [ <a href="<?php echo $action['href']; ?>" target="<?php echo $action['target']; ?>"><?php echo $action['text']; ?></a> ]
                <?php } ?></td>
            </tr>
            <?php } ?>
            <?php } else { ?>
            <tr>
              <td class="center" colspan="9"><?php echo $text_no_results; ?></td>
            </tr>
            <?php } ?>
          </tbody>
        </table>
      </form>
      <div class="pagination"><?php echo $pagination; ?></div>
    </div>
  </div>
</div>
<script type="text/javascript">//<![CDATA[
function filter() {
	url = 'index.php?route=news/category&token=<?php echo $token; ?>';
	var filter_name = $('input[name=\'filter_name\']').attr('value');
	
	if (filter_name) {
		url += '&filter_name=' + encodeURIComponent(filter_name);
	}
	
	/*filter_category*/
	var parent_id = $('select[name=\'parent_id\']').attr('value');
	if (parent_id) {url += '&parent_id=' + encodeURIComponent(parent_id);	}
	
	
	var filter_status = $('select[name=\'filter_status\']').attr('value');
	
	if (filter_status != '*') {
		url += '&filter_status=' + encodeURIComponent(filter_status);
	}	

	location = url;
}
//]]></script>
 
<script type="text/javascript">//<![CDATA[

$('#form input').keydown(function(e) {
	if (e.keyCode == 13) {
		filter();
	}
});
//]]></script>
<?php echo $footer; ?>